export default class Video {
  constructor(basicCesium) {
    this.basicCesium = basicCesium
    this.viewer = basicCesium.viewer
    this.clock = basicCesium.viewer.clock;
    this.entities = basicCesium.viewer.entities;

    this.initEntity()
  }

  initEntity() {
    let dom = document.getElementById("video");
    let values = this.entities.values;
    if (values.length > 0) return false;
    this.entities.add({
      polygon: {
        hierarchy: {
          positions: Cesium.Cartesian3.fromDegreesArray([
            114.0, 30.0,
            114.3, 30.0,
            114.3, 30.2,
            114.0, 30.2
          ])
        },
        material: dom,
        height: 10000,
        outline: false // height is required for outline to display
      }
    });
    this.viewer.zoomTo(this.entities);
    let synchronizer = new Cesium.VideoSynchronizer({
      clock: this.clock,
      element: dom
    });

    this.viewer.camera.flyTo({
      destination: this.basicCesium.lnglatToWorld(114.15, 30.1,80000),
      orientation: {
        heading: this.viewer.camera.heading,
        pitch: this.viewer.camera.pitch,
        roll: this.viewer.camera.roll,
      },
      duration: 0.0,
    })
  }

  clearAll() {
    this.entities.removeAll();
  }
}